package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.constant.Constant;
import com.itany.mapper.BookMapper;
import com.itany.pojo.Book;
import com.itany.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2019-09-18 下午3:08
 * Description：<描述>
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Transactional(readOnly = true)
    public  PageInfo<Book> findAllBook(Integer page, Integer rows,Book book) {
        PageHelper.startPage(page, rows);
        List<Book> books = bookMapper.selectAll(book);
        PageInfo<Book> info = new PageInfo<Book>(books);
        return info;
    }

    public void addBook(Book book) {
        book.setFlag(Constant.EXAMINE_UNCERTAIN);
        String bookName = book.getBookName();
        Book b=bookMapper.selectByName(bookName);
        if(null!=b){
            Integer number = b.getNumber();
            Integer bookNumber = book.getNumber();

        }
        bookMapper.insertBook(book);
    }

    public void modifyStatusEnable(Book book) {
        book.setFlag(Constant.BOOK_ENABLE_STATUS);
        bookMapper.updateStatusEnable(book);
    }

    public void modifyStatusDisable(Book book) {
        book.setFlag(Constant.BOOK_DISABLE_STATUS);
        bookMapper.updateStatusDisable(book);
    }

    public void modifyBook(Book book) {
        bookMapper.updateBook(book);
    }
}